package com.zkt.recommend.application.interceptor;

import com.zkt.recommend.common.constants.RecommendConstant;
import com.zkt.recommend.common.context.LoginContextHolder;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * @author 赵开泰
 * @program jc-club
 * @date 2025/3/23
 * @description 登录信息拦截器
 **/

public class LoginInterceptor implements HandlerInterceptor {
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		String loginId = request.getHeader(RecommendConstant.LOGIN_ID);
		LoginContextHolder.set(RecommendConstant.LOGIN_ID, loginId);
		return true;
	}
	
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
		LoginContextHolder.remove();
	}
}